<template>
	<view class="subscribe">
		<image class="yuyuebanner" src="../../static/yuyuebanner.png"></image>
		
		<view class="subscribeview">
			<view class="subscribeview-title">{{info.name}}</view>
			<view class="subscribeview-1">
				<view class="subscribeview-1-title">请选择预约日期</view>
				
				<view class="subscribeview-1-flex">
				
					<view class="subscribeview-1-flex-view " :class="item.date == date && datetype ==0 ? 'actity':''" @click="dateselectClick(item)" v-for="(item,index) in dateall">
						<view>{{item.week}}</view>
						<view>{{item.date}}</view>
					</view>
					
					<view class="subscribeview-1-flex-view" :class="datetype ==1 ? 'actity':''">
						<picker mode="date" :value="date"  @change="bindDateChange">
						<view>自定义</view>
						<view>{{datetype == 0 ? "点击选择": date}}</view>
						</picker>
					</view>
				</view>
			</view>
			
			<view class="subscribeview-1">
				<view class="subscribeview-1-title">请选择预约时段</view>
				<view class="subscribeview-2-flex">
					<view class="subscribeview-2-flex-view" :class="time =='上午'  ? 'actity':''"  @click="timeClick('上午')">
						<view>上午</view>
					</view>
					<view class="subscribeview-2-flex-view" :class="time =='下午' ? 'actity':''"  @click="timeClick('下午')">
						<view>下午</view>
					</view>
				</view>
			</view>
			
			<view class="subscribeview-1">
				<view class="subscribeview-1-title">请填写基本信息</view>
				
				<view class="subscribeview-1-input">
					<view>姓&#8195;&#8195;名：</view>
					<input  type="text" v-model="name" placeholder="请填写姓名" placeholder-style="font-size:28rpx"/>
				</view>
				
				<view class="subscribeview-1-input">
					<view>联系方式：</view>
					<input  type="text" v-model="phone" placeholder="请填写联系方式" placeholder-style="font-size:28rpx"/>
				</view>
				
				<view class="subscribeview-1-input">
					<view>预约服务：</view>
					
					<picker @change="bindPickerChange" :value="index" :range="array">
						<view v-if="index >=0">{{array[index]}}</view>
						<view class="huiwei" v-else> 请选择预约服务</view>
					</picker>
				</view>
				<!-- <view class="subscribeview-1-input">
					<view>备注：</view>
					<textarea v-model="remark"  placeholder="请填写备注" placeholder-style="font-size:28rpx"></textarea>
				</view> -->
			</view>	
			
			
			<view class="buttom" @click="buttomClick()">提交预约</view>
		</view>
		
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info : [],
				array: [],
				index:  -1,
				dateall : [],
				date : '',
				name : '',
				phone: '',
				remark: '',
				yycategory_id : '',
				datetype  : 0,
				time  : '上午'
			}
		},
		onLoad(e) {
			console.log(e);
			this.getall(e);
		},
		methods: {
			timeClick(e){
				this.time = e;
			},
			buttomClick(e){
				let that = this;
				if(that.index == -1){
					uni.showToast({
						title: '请选项预约类目',
						icon: 'none'
					});return;
				}
				var parmes ={
					'name' : that.name,
					'phone': that.phone,
					'time' : that.time,
					'yycategory_id' : that.array[that.index],
					'date' : that.date,
					'shop_id':that.info['id']
				}
				that.$api.setadd(parmes).then(res=>{
					if(res.code == 1){
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
						setTimeout(function() {
						uni.redirectTo({
						  url: '/pages/contactus/contactus'
						});
						}, 2000)
						
						
					}
					console.log(res);
				})
				console.log(parmes);
			},
			dateselectClick(e){
				this.date  = e.date;
				this.datetype  = 0;
			},
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.index = e.detail.value
			},
			bindDateChange:function(e){
				this.datetype  = 1;
				 this.date = e.detail.value
			},
			getall(e){
				let that  = this;
				that.$api.yycategoryall({}).then(res=>{
					that.array  = res.data.list;
				})
				that.$api.yuyuedate({}).then(res=>{
					that.dateall   = res.data.list;
				})
				that.$api.shopinfo({'id':e.shop_id}).then(res=>{
					that.info   = res.data.info;
				})
				
			}
		}
	}
</script>

<style lang="less">
	.subscribe {
		height: 110vh;
		background-color: #02274b;
		color: #333;
		.yuyuebanner {
			width: 750rpx;
			height: 238rpx;
		}
		.subscribeview {
			width: 670rpx;
			min-height: 740rpx;
			background-color: #fff;
			margin: auto;
			border-radius: 20rpx;
			position: absolute;
			left: 0; right: 0;
			margin-top: -30rpx;
			padding: 16rpx;
			.subscribeview-title {
				font-size: 38rpx;
				font-weight: bold;
				line-height: 120rpx;
				border-bottom: 2rpx solid #e8e8e8;
			}
			.subscribeview-1 {
				.subscribeview-1-title {
					font-size: 30rpx;
					font-weight: bold;
					margin-left: 28rpx;
					padding-bottom: 20rpx;
					padding-top: 30rpx;
				}
				.subscribeview-1-flex {
					display: flex;
					flex-wrap: wrap;
					color: #707070;
					.subscribeview-1-flex-view {
						border: 2rpx solid #e8e8e8;
						text-align: center;
						padding: 10rpx;
						border-radius: 20rpx;
						font-size: 28rpx;
						line-height: 46rpx;
						margin-left: 28rpx;
						width: 160rpx;
						margin-bottom: 20rpx;
					}
				}
				.subscribeview-2-flex {
					display: flex;
					color: #707070;
					.subscribeview-2-flex-view {
						border: 2rpx solid #e8e8e8;
						text-align: center;
						padding: 10rpx;
						border-radius: 20rpx;
						font-size: 28rpx;
						line-height: 46rpx;
						margin-left: 28rpx;
						width: 260rpx;
						margin-bottom: 20rpx;
					}
				}
				.subscribeview-1-input {
					display: flex;
					width: 610rpx;
					margin: auto;
					line-height: 70rpx;
					margin-bottom: 20rpx;
					view {
						width: 160rpx;
					}
					input,picker {
						width: 410rpx;
						border: 2rpx solid #e8e8e8;
						height: 70rpx;
						border-radius: 10rpx;
						padding-left: 20rpx;
						view {
							width: 100%;
						}
						.huiwei {
							color: #707070;
							font-size: 28rpx;
						}
					}
					
				}
			}
		}
		.buttom {
			width: 660rpx;
			line-height: 100rpx;
			background-color: #02274b;
			margin: auto;
			margin-top: 60rpx;
			text-align: center;
			color: #fff;
			border-radius: 30rpx;
		}
	}
	.actity {
		border: 2rpx solid #02274b !important;
		color: #02274b !important;
	}
</style>
